package fun.yao.common.uitls;

import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;

public class CommonUtil {

    /**
     * <p>方法名称: </p>
     * <p>功能描述:字符串填充 </p>
     * <p>参数介绍:需要填充的字符串;填充的字符;填充长度;左右标志 </p>
     * modify by csl 2008.09.19 优化
     */
    public static String FILL(String s, char c, int n, char f)
    {
        int iByteLen = MsgUtil.StringToBytes(s).length;
        if ( iByteLen  >= n)
        {
            return s;
        } else
        {
            byte[] fillChars = new byte[n-iByteLen];
            for ( int i = 0 ; i < fillChars.length ; i++ )
                fillChars[i] = (byte)c;

            if ( f == 'L' ) //左补
            {
                return new String(fillChars) + s;
            }else //右补
            {
                return s + new String(fillChars) ;
            }

        }
    }

}
